package member.base.service;

import m.common.model.util.ModelQueryList;
import m.common.model.util.ModelUpdateUtil;
import m.common.model.util.QueryCondition;
import m.common.service.Service;
import member.base.model.LevelUpSet;
import member.base.model.MemberInfo;
import member.base.model.StatusModel;

public class LevelUpSetService extends Service {
    public void autoUpSet(String memberOid) throws Exception {
        MemberInfo member= getService(MemberInfoService.class).get(memberOid);
        LevelUpSet up= ModelQueryList.getModel(LevelUpSet.class,new String[]{"*","beforeLevel.*","afterLevel.*"},
            QueryCondition.and(
                QueryCondition.eq("beforeLevel.oid",member.getLevel().getOid()),
                QueryCondition.eq("status", StatusModel.StatusEnabled)
            )
        );;
        if(null!=up){
            //同时满足使用金额和订单金额到达目标时升级
            if(member.getUseMoney()>=up.getUseMoney()&&member.getOrderNum()>=up.getOrderNum()){
                member.setLevel(up.getAfterLevel());
                ModelUpdateUtil.updateModel(member,"level.oid");
            }
        }
    }
}
